<template>
	<view>
    <navbar></navbar>
    <template v-if="!loading">
      <view v-if="0 < list.length" class="container">
        <goods :scroll-top="scrollTop" :info="item" @finished="countdownFinished"
               v-for="item in list" :key="item.goods_id"></goods>
      </view>
      <view v-else class="yoshop-notcont">
        <text class="dy-iconfont icon-empty"></text>
        <text class="cont">无搜索结果</text>
      </view>
    </template>
	</view>
</template>

<script>
  const app = getApp();
	export default {
		data() {
			return {
        scrollTop: 0,
        list: [],
        page: 1,
        loading: true,
        hasMore: false,
			}
		},
    onLoad(options) {
		  this.search = options.search || '少女';
		  this.requestData();
    },
    onReachBottom() {
      if (!this.loading && this.hasMore) {
        this.requestData();
      }
    },
    onPageScroll(e) {
      this.scrollTop = e.scrollTop;
    },
		methods: {
			requestData: function() {
			  this.loading = true;
        app._get('goods/lists', {
              page: this.page,
              sortType: 'all',
              sortPrice: 0,
              category_id: 0,
              search: this.search
            }, (res) => {
              let {
                data,
                total
              } = res.data.list;
              this.list = this.list.concat(data);
              let hasMore = total > this.list.length;
              if (hasMore) {
                this.page++;
              }
              this.hasMore = hasMore;
            }, null, () => {
              this.loading = false;
            }
        );
      },
      // 倒计时结束
      countdownFinished: function() {
        this.requestData();
      },
		}
	}
</script>
<style>
  page {
    background: #000!important;
  }
</style>
<style lang="scss" scoped>

.container {
  padding: 40rpx;
}
</style>
